home *** CD-ROM | disk | FTP | other *** search
- /*
- * The original copyright owners of the accompanying source code files have
- * agreed to place such code into the public domain. Accordingly, anyone
- * who receives or obtains a copy of such source code is freely entitled to
- * reproduce, use and otherwise exploit such code (including the right to
- * make derivative works), at his/her own risk and expense, without any
- * obligation or liability to the original copyright owners.
- *
- * We would appreciate (but do not require) that the following message be
- * included in any derivative works:
- *
- * "Portions of this program were developed by Peter Broadwell, Rob Myers
- * and Robin Schaufler while working in Silicon Valley."
- *
- * The accompanying source code files and related documentation materials
- * are distributed on an "AS IS" basis, without any warranties or
- * guarantees of any kind. All implied warranties, including the implied
- * warranties of merchantability and of fitness for any particular purpose,
- * are expressly disclaimed.
- */
- #include "gl.h"
- #include "geom.h"
- #include "class.h"
- #include "selectors.h"
- #include "classIds.h"
- #include "colors.h"
- #include "mbox.h"
- #include "individual.h"
- #include "camera.h"
- #include "panel.h"
- #include "valuator.h"
- #include "menu.h"
- #include "pick.h"
- #include "objIds.h"
-
- extern masterPanel mPanelTemplate;
- extern masterPanel *thePanel;
- extern panel panelTemplate;
- extern colorPanel colorPanelTemplate;
- extern point2d curWindow;
- extern point2df scalePanel;
- extern int unsophistication;
-
- extern panel *makeValuator(), *makeValuatorf(), *makeValDelta(), *makeMenu();
- extern panel *makeValHue(), *makeValVal();
-
- /*
- * initialize a panel
- */
- panel *
- makePanel(list, dad, ScrArea, paintObj)
- register panel *list, *dad;
- register rectangle *ScrArea;
- Object paintObj;
- {
- register panel *aPanel;
-
- if ((aPanel = (panel *)clone(&panelTemplate)) == NULL)
- return list;
-
- aPanel->next = list;
- aPanel->kids = NULL;
- aPanel->dad = dad;
- aPanel->area = *ScrArea;
- aPanel->painter = paintObj;
-
- return aPanel;
- }
-
- /*
- * initialize a color panel
- */
- panel *
- makeColorPanel(list, dad, ScrArea, clientColor)
- register panel *list, *dad;
- register rectangle *ScrArea;
- int clientColor;
- {
- register colorPanel *aPanel;
- RGBvalue r, g, b;
-
- if ((aPanel = (colorPanel *)clone(&colorPanelTemplate)) == NULL)
- return list;
-
- aPanel->base.next = list;
- aPanel->base.kids = NULL;
- aPanel->base.dad = dad;
- aPanel->base.area = *ScrArea;
- aPanel->base.painter = NULL;
-
- gmcolor(clientColor, &r, &g, &b);
-
- /* convert from rgb to hsv and stuff it */
-
- aPanel->hue = 0;
- aPanel->satur = 0;
- aPanel->value = 0;
- aPanel->clientColor = clientColor;
-
- return (panel *)aPanel;
- }
-
- emptyPanel(p)
- register panel *p;
- {
- freePanel(p->next); /* discard old dependant panels */
- freePanel(p->kids);
- p->next = NULL;
- p->kids = NULL;
-
- if (p->painter == NULL) {
- buildFloor(&p->area, MASTERFLOOR);
- p->painter = (Object)MASTERFLOOR;
- }
- ((masterPanel *)p)->highwater.x = 0;
- ((masterPanel *)p)->highwater.y = 0;
- }
-
- /*
- * re-initialize the master control panel's subtree of panels
- */
- initPanel(p)
- register panel *p;
- {
- int flags;
- rectangle r, rw, rl;
- point2d inset, button;
- extern camera *theCamera;
- extern panel *makeValuator(), *makeValDelta(), *makeMenu();
-
- freePanel(p->next); /* discard old dependant panels */
- freePanel(p->kids);
- p->next = NULL;
- p->kids = NULL;
-
- if (p->painter == NULL) {
- buildFloor(&p->area, MASTERFLOOR);
- p->painter = (Object)MASTERFLOOR;
- }
-
- ((masterPanel *)p)->highwater.x = 255;
- ((masterPanel *)p)->highwater.y = 205;
-
- /* leftright/updown camera control */
- flags = CLIPOUT;
- setrect(&r, 10,20, 150,150);
- setpt2d(&inset, 0,0);
- setrect(&rw, -60,-30, 120,60);
- setrect(&rl, -5400,0, 5400,1800);
- buildCam1(&r, CAM1);
- p->kids = makeValDelta(p->kids, p, flags, &r, &inset, &rw,
- &theCamera->me.rotation.z,
- &theCamera->me.rotation.y, &rl, CAM1);
-
-
- /* zoom camera control */
- flags = CLIPOUT;
- setrect(&r, 170,20, 75,150);
- setpt2d(&inset, 0,0);
- setrect(&rw, 0,-15, 0,30);
- setrect(&rl, 0,200, 0,1700);
- buildCam2(&r, CAM2);
- p->kids = makeValDelta(p->kids, p, flags, &r, &inset, &rw,
- NULL,
- &theCamera->zoom, &rl, CAM2);
-
- /* reset camera control */
- flags = NULL;
- setrect(&r, 220,20, 30,30);
- setpt2d(&button, 1, 1);
- buildCam3(&r, CAM3, CAM3H);
- p->kids = makeMenu(p->kids, p, flags, &r,&button,theCamera,HOME,CAM3,CAM3H);
-
- /* sophistication control */
- flags = NULL;
- setrect(&r, 10,180, 240,25);
- setpt2d(&inset, 6,0);
- setrect(&rw, 0,0, 100,0);
- buildSoph(&r, SOPH, SOPHH);
- p->kids = makeValuator(p->kids, p, flags, &r, &inset, &rw,
- &unsophistication,
- NULL, SOPH, SOPHH);
- }
-
- /*
- * refresh the control panel, updating it as necessary
- */
- drawControls(aPanel)
- masterPanel *aPanel;
- {
- static inited = FALSE;
-
- if (! inited) {
- Msg(aPanel, INIT, NOARG, NULL);
- inited = TRUE;
- }
-
- makeobj((Object)aPanel);
- initnames();
- loadname(0);
- pushname(0);
- pushLongName(aPanel);
-
- Msg(aPanel, DRAW, NOARG, NULL);
-
- popLongName();
- closeobj();
- }
-
-
- /*
- * draw the panel tree, beginning with the firstPanel
- */
- drawPanel(firstPanel)
- register panel *firstPanel;
- {
- register panel *p;
-
- for (p = firstPanel; p; p = p->next) {
- pushmatrix();
- pushLongName(p);
- translate((float)p->area.orig.x, (float)p->area.orig.y, 0.0);
- fishWritemask(FOREGROUND);
- callobj(p->painter);
- Msg(p, DRAWTRACKER, NOARG, NULL);
- popLongName();
-
- /* printf("drawPanel: 0x%x (class %d) about to draw kids 0x%x\n",
- p, p->myClass->classId, p->kids); /* */
- drawPanel(p->kids);
- popmatrix();
- }
- }
-
- /*
- * initialize a color-editing panel with two interconnected
- * valuators, with feedback as to the current color
- */
- initColorVals(p, flags, scrArea, clientColor)
- register panel *p;
- int flags;
- register rectangle *scrArea;
- int clientColor;
- {
- rectangle area;
- point2d inset;
- panel *dad;
- static nextCid = COLORVAL1;
-
- setpt2d(&inset, 0,0);
- buildCol(scrArea, color, nextCid, nextCid+1, nextCid+2);
- dad = p->kids = makeColorPanel(p->kids, p, scrArea, clientColor);
- p = dad;
- area.orig.x = 0;
- area.orig.y = 0;
- area.extent.x = (3*(scrArea->extent.x-10))/4;
- area.extent.y = scrArea->extent.y;
- p->kids = makeValHue(p->kids, p, flags, &area, &inset, color,
- nextCid, nextCid+2);
- area.orig.x = area.extent.x + 10;
- area.extent.x = (scrArea->extent.x-10)/4;
- p->kids = makeValVal(p->kids, p, flags, scrArea, &inset, color,
- nextCid+1, nextCid+2);
-
- /* bump parent's area */
- dad->area.extent.x =
- max(p->area.extent.x, scrArea->orig.x+scrArea->extent.x);
- dad->area.extent.y =
- max(p->area.extent.y, scrArea->orig.y+scrArea->extent.y);
-
- nextCid += 3;
- }
-
- /*
- * initialize a plain vanilla absolute valuator consisting of a box
- * containing a sliding bar, and a label below it.
- */
- initVanillaVal(p, fr, to, curval, label)
- panel *p;
- int fr, to; /* range of values */
- int *curval; /* initial value */
- char *label;
- {
- int flags;
- rectangle scrArea, worldArea;
- point2d inset;
-
- flags = NULL;
- setrect(&scrArea, 0, getheight(), 50, 67);
- setpt2d(&inset, 0,2);
- if (p->kids) {
- scrArea.orig.x = p->kids->area.orig.x + p->kids->area.extent.x + 10;
- }
- setrect(&worldArea, 0, to, 0, fr - to);
- bldVanillaVal(&scrArea, label, curval, label);
- p->kids = makeValuator(p->kids, p, flags, &scrArea, &inset, &worldArea,
- NULL, curval, label, curval);
- /* bump parent's area */
- p->area.extent.x = max(p->area.extent.x, scrArea.orig.x+scrArea.extent.x);
- p->area.extent.y = max(p->area.extent.y, scrArea.orig.y+scrArea.extent.y);
- }
-
- /*
- * initialize a plain vanilla absolute floating point valuator
- * consisting of a box containing a sliding bar, and a label below it.
- */
- initVanillaValf(p, fr, to, curval, label)
- panel *p;
- float fr, to; /* range of values */
- float *curval; /* initial value */
- char *label;
- {
- int flags;
- rectangle scrArea;
- rectanglef worldArea;
- point2d inset;
-
- flags = NULL;
- setrect(&scrArea, 0, getheight(), 50, 67);
- setpt2d(&inset, 0,2);
- if (p->kids) {
- scrArea.orig.x = p->kids->area.orig.x + p->kids->area.extent.x + 10;
- }
- setrect(&worldArea, 0.0, to, 0.0, fr - to);
- bldVanillaVal(&scrArea, label, curval, label);
- p->kids = makeValuatorf(p->kids, p, flags, &scrArea, &inset, &worldArea,
- NULL, curval, label, curval);
- }
-
-
- /*
- * gffree the panel tree, beginning with the firstPanel
- */
- freePanel(firstPanel)
- register panel *firstPanel;
- {
- register panel *p, *nextp;
-
- for (p = firstPanel; p; p = nextp) {
- nextp = p->next;
- /*
- delobj(p->painter);
- switch(p->them.me.myClass->classId) {
- case VALUATOR:
- delobj(((valuator *)p)->tracker);
- break;
- case VALUATORF:
- delobj(((valuatorf *)p)->tracker);
- break;
- case VALMESG:
- delobj(((valmesg *)p)->tracker);
- break;
- case VALMESGF:
- delobj(((valmesgf *)p)->tracker);
- break;
- case MENU:
- delobj(((menu *)p)->highlight);
- break;
- case CHOICE:
- delobj(((choice *)p)->highlight);
- break;
- case CHOICEF:
- delobj(((choicef *)p)->highlight);
- break;
- default:
- break;
- }
- */
- freePanel(p->kids);
- dontdo(p);
- gffree(p);
- }
- }
-
- panel *curPanel = NULL;
-
- /*
- * begin picking on a panel (button goes down on it)
- */
- bselPanel(self, argtype, hit)
- register panel *self;
- long argtype;
- hitstruct *hit;
- {
- /* printf("bselPanel: BEGIN SELECT on 0x%x, class %d, curPanel 0x%x\n",
- self, ((inst *)self)->myClass->classId, curPanel); /* */
-
- curPanel = self; /* hit processing all goes to pen-goes-down panel */
- convertHit(curPanel, hit);
- Msg(curPanel, SELECT, argtype, hit);
- }
-
- /*
- * begin picking on a new panel (button wanders into it while down)
- */
- nselPanel(self, argtype, hit)
- register panel *self;
- long argtype;
- hitstruct *hit;
- {
- /* printf("nselPanel: NEW SELECT on 0x%x, class %d, curPanel 0x%x\n",
- self, ((inst *)self)->myClass->classId, curPanel); /* */
- }
-
-
- /*
- * continue picking on a panel (button remains down on it)
- */
- cselPanel(self, argtype, hit)
- register panel *self;
- long argtype;
- hitstruct *hit;
- {
- /* printf("cselPanel: CONTINUE SELECT on 0x%x, class %d, curPanel 0x%x\n",
- self, ((inst *)self)->myClass->classId, curPanel); /* */
-
- if (curPanel) {
- convertHit(curPanel, hit);
- Msg(curPanel, SELECT, argtype, hit);
- }
- }
-
- /*
- * end picking on a panel (button goes up on it)
- */
- eselPanel(self, argtype, hit)
- register panel *self;
- long argtype;
- hitstruct *hit;
- {
- /* printf("eselPanel: END SELECT on 0x%x, class %d, curPanel 0x%x\n",
- self, ((inst *)self)->myClass->classId, curPanel); /* */
-
- if (curPanel) {
- if (self != curPanel) {
- Msg(curPanel, ENDSELECT, argtype, hit);
- }
- else {
- convertHit(curPanel, hit);
- Msg(curPanel, SELECT, argtype, hit);
- Msg(curPanel, RESET, argtype, hit);
- curPanel = NULL;
- }
- }
- }
-
- /*
- * abort picking on a panel (pen-down goes out of bounds)
- */
- kselPanel(self, argtype, hit)
- register panel *self;
- long argtype;
- hitstruct *hit;
- {
- /* printf("kselPanel: KILL SELECT on 0x%x, class %d, curPanel 0x%x\n",
- self, ((inst *)self)->myClass->classId, curPanel); /* */
- }
-
- /*
- * no longer picking on a panel (button leaves it while down)
- */
- oselPanel(self, argtype, hit)
- register panel *self;
- long argtype;
- register hitstruct *hit;
- {
- /* printf("oselPanel: OLD SELECT on 0x%x, class %d, curPanel 0x%x\n",
- self, ((inst *)self)->myClass->classId, curPanel); /* */
-
- /*
- * if passing out of legal control panel area, send kill select
- */
- if (checkForKillPanel(self, argtype, hit)) {
- if (curPanel) {
- Msg(curPanel, KILLSELECT, argtype, hit);
- curPanel = NULL;
- }
- }
- else {
- /*
- * otherwise, handle it like it was just any other continue select
- */
- Msg(self, CONTSELECT, argtype, hit);
- }
-
- }
-
- /*
- * kill current panel-selection process if picking passes out of
- * control panel's viewport
- */
- checkForKillPanel(self, argtype, hit)
- register panel *self;
- long argtype;
- register hitstruct *hit;
- {
- hitstruct dummy;
-
- dummy = *hit;
-
- convertHit(NULL, &dummy); /* convert hit into viewport-relative coords */
- if (dummy.x <=0) { /* if pen-down passes into other viewport */
- return TRUE; /* invalidate further pen-downs in panels */
- } /* until next bselPanel */
- else return FALSE;
- }
-
- /*
- * process a selection in a panel
- */
- selectPanel(self, argtype, hit)
- register panel *self;
- long argtype;
- register hitstruct *hit;
- {
- /* printf("selectPanel: selected panel 0x%x, class %d, curPanel 0x%x\n",
- self, ((inst *)self)->myClass->classId, curPanel); /* */
-
- /* printf("selectPanel: ignoring hit at %d, %d\n", hit->x, hit->y);
- /* */
- }
-
- /*
- * process a deselection in a panel
- */
- deselectPanel(self)
- register panel *self;
- {
- /* printf("deselectPanel: deselect panel 0x%x, class %d, curPanel 0x%x\n",
- self, ((inst *)self)->myClass->classId, curPanel); /* */
- }
-
- /*
- * convert hit into Panel's local coordinate space
- */
- convertHit(aPanel, hit)
- register panel *aPanel;
- register hitstruct *hit;
- {
- /* convert screen coordinates into viewport-relative coords */
- hit->x = (hit->x - curWindow.y) * scalePanel.x;
- hit->y = (curWindow.y - hit->y) * scalePanel.y;
- /*
- printf("convertHit: viewport hit = %d, %d\n", hit->x, hit->y);
- /* */
-
- /* convert viewport coords into panel-relative coords */
- while(aPanel) {
- hit->x -= aPanel->area.orig.x;
- hit->y -= aPanel->area.orig.y;
- /*
- printf("\t in panel loop, orig = %d, %d\n",
- aPanel->area.orig.x, aPanel->area.orig.y);
- /* */
- aPanel = aPanel->dad;
- }
- /*
- printf("convertHit: panel hit = %d, %d\n", hit->x, hit->y);
- /* */
- }
-
- /*
- * convert a point in Panel's local coordinate space into viewport coords
- */
- globalPoint(aPanel, aPoint)
- register panel *aPanel;
- register point2d *aPoint;
- {
- while(aPanel) {
- aPoint->x += aPanel->area.orig.x;
- aPoint->y += aPanel->area.orig.y;
- /*
- printf("globalPoint in panel loop, orig = %d, %d\n",
- aPanel->area.orig.x, aPanel->area.orig.y);
- /* */
- aPanel = aPanel->dad;
- }
- }
-
- /*
- * convert a floating point in Panel's local space into viewport coords
- */
- globalPointf(aPanel, aPoint)
- register panel *aPanel;
- register point2df *aPoint;
- {
- while(aPanel) {
- aPoint->x += (float)aPanel->area.orig.x;
- aPoint->y += (float)aPanel->area.orig.y;
- /*
- printf("globalPointf in panel loop, orig = %d, %d\n",
- aPanel->area.orig.x, aPanel->area.orig.y);
- /* */
- aPanel = aPanel->dad;
- }
- }
-
- /*
- * read thePanel's current highwater mark
- */
- getHighwater(aPanel)
- register panel *aPanel;
- {
- int highwater = 0;
-
- while(aPanel->dad) {
- highwater += aPanel->area.orig.y;
- aPanel = aPanel->dad;
- }
-
- return thePanel->highwater.y - highwater;
- }
-
- /*
- * set thePanel's current highwater mark
- */
- setHighwater(newval)
- int newval;
- {
- thePanel->highwater.y = newval;
- }
-
- /*
- * increment thePanel's current highwater mark
- */
- bumpHighwater(incr)
- int incr;
- {
- thePanel->highwater.y += incr;
- }
-